﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HousingInfo.Library;

namespace WebHousingInfo
{
    public partial class GuiBaiMoiDienDan : System.Web.UI.Page
    {
        private static string mode = null, mode_edit = null;
        private static ForumNewsBO forumnewsbo;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UserName"] == null)
                    Response.Redirect("DangNhap.aspx");
                mode = Request.QueryString["categoryid"];
                if (mode != null)
                {

                }
            }
        }

        protected void btndangtin_Click(object sender, EventArgs e)
        {
            if (Session["UserName"] == null)
                Response.Redirect("DangNhap.aspx");
            if (mode_edit != null)
            {

            }
            else
            {
                forumnewsbo = ForumNewsBO.NewForumNewsBO();
                forumnewsbo.UserName = Session["UserName"].ToString();
                forumnewsbo.Title = txttieude.Text;
                forumnewsbo.SubTopicForumID = Convert.ToInt32(mode);
                forumnewsbo.CreatedDate = DateTime.Now;
                forumnewsbo.UpdatedDate = DateTime.Now;
                forumnewsbo.ForumNewsContent = txtnoidung.Text;
                forumnewsbo.ViewCount = 0;
                try
                {
                    forumnewsbo.Save();
                    Response.Redirect("DienDanTinTheoChuDe.aspx?idsub=" + mode);
                }
                catch
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success", "alert('Đăng tin thất bại !!!')", true);
                    return;
                }
            }
        }
    }
}
